package com.xunyun.kotlinwc.main.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.xunyun.kotlinwc.main.model.BannerBean
import com.youth.banner.adapter.BannerAdapter

/**
 * @author gl
 * @date 2021/9/9
 * @desc
 */
class ImageAdapter(var context: Context, images: List<BannerBean>) :
    BannerAdapter<BannerBean, ImageAdapter.BannerViewHolder>(images) {


    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        var imageView = ImageView(parent?.context)
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(imageView)
    }

    override fun onBindView(
        holder: BannerViewHolder?,
        data: BannerBean?,
        position: Int,
        size: Int
    ) {
        data?.let { data ->
            holder?.let { viewHolder ->
                viewHolder.imageView?.let { imageView ->
                    data.imagePath?.let { imagePath ->
                        Glide.with(context)
                            .load(imagePath)
                            .into(imageView)
                    }
                }
            }
        }


    }


    class BannerViewHolder(var imageView: ImageView) : RecyclerView.ViewHolder(imageView)


}